package com.yz.platform.modules.biz.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yz.platform.common.utils.PageUtils;
import com.yz.platform.common.utils.Query;
import com.yz.platform.common.utils.R;
import com.yz.platform.modules.biz.entity.AppEntity;
import com.yz.platform.modules.biz.service.AppService;
import com.yz.platform.modules.sys.controller.AbstractController;


/**
 * @author lin
 * @email
 * @date 2017-10-23 15:42:54
 */
@RestController
@RequestMapping("app")
public class AppController extends AbstractController {
    @Autowired
    private AppService appService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("app:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<AppEntity> appList = appService.queryList(query);
        int total = appService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(appList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{appId}")
    @RequiresPermissions("app:info")
    public R info(@PathVariable("appId") Integer appId) {
        AppEntity app = appService.queryObject(appId);

        return R.ok().put("app", app);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("app:save")
    public R save(@RequestBody AppEntity app) {

        app.setCreateTime(new Date());
        app.setCreateUser(getUserId().intValue());
        appService.save(app);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("app:update")
    public R update(@RequestBody AppEntity app) {
        appService.update(app);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("app:delete")
    public R delete(@RequestBody Integer[] appIds) {
        appService.deleteBatch(appIds);

        return R.ok();
    }

}
